-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Fix memory issues when installing models on Windows #8652
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Wrap gguf.GGUFReader and then use a context manager to load memory-mapped GGUF files, so that they will automatically close properly when no longer needed. Should prevent the 'file in use in another process' errors on Windows.
Additional check for cached state_dict as path is now optional - should solve model manager 'missing' this and the resultant memory errors.
|
I'm sorry but I can't seem to appease ruff here, even when configuring mine with this repo's pyproject.toml. |
|
@gogurtenjoyer a few equestions that are more related to Model Manager v3 than to your PR, but I encountered them while testing on your PR.
Are these known issues with FLUX models? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is at least one .gguf file that works with main and causes a core dump when used with this PR. I tested using flux1-schnell-Q2_K.gguf.
I believe this is related to the WrappedGGUFReader.
|
@lstein - thanks, I'll try that flux schnell model to see what's going on.
|
|
Okay, the Flux Schnell Q2 linked above installed and ran correctly for me on Windows - is the core dump during generating, or the install? Here's a few more GGUFs to test (and which we used for testing when trying to triage the Windows issue) - the GGUF sizes/versions are in the buttons along the top: https://civitai.com/models/630820?modelVersionId=944736 |
No longer attempting to delete internal object.
|
Suspect the issue is with using @lstein could you try with this latest fix? @JPPhoto tested as well on Linux (WSL2 I believe!) and it seems to do the trick. |
Summary
Windows treats file handles differently than MacOS and Linux - Model Manager v3 has exposed some issues here, so here's a few patches to solve this. I wrote more but then the power went out, and I'm not rewriting all of that, but I wanted to make sure to thank @skunkworxdark for catching and fixing a serious memory issue.
Related Issues / Discussions
Closes:
#8644
#8636
#8628
#8627
QA Instructions
To test, import various models from Starter Models and elsewhere: GGUF files, Safetensors files, particularly large ones, and Diffusers multi-file models. This fix is specifically for Windows, but the changes should benefit every OS and not break anything on MacOS and Linux. Tested on MacOS and Windows so far.
Merge Plan
Changes the GGUF loader, and import_state_dict in model_on_disk.py - shouldn't conflict with anything; mostly small/remote changes.
Checklist
What's Newcopy (if doing a release after this PR)